var controller = {}

controller.register = function(req, res, next){
    var qlSearch = 'select tel from user where tel =' + req.query.account;
    var qlInsert = 'insert into user (id, name, tel, pw) values ("0", "'+ req.query.name + '", "' + req.query.account + '", "' + req.query.password +'")';
    
    conn.query(qlSearch, function(err, results, fields){
        if (err) throw err;
        if (!results || results.length <=0){
            
            conn.query(qlInsert, function(err, results, fields){
                if (err) throw err;
                console.log(results);
                res.send({
                    code:200
                })
            });

        } else {
            console.log('该用户已经存在');
            res.send({
                code: 400
            });
        }
    })
}

module.exports = controller;